package com.rcw.filelib.adapter;

import android.content.Context;
import android.text.format.Formatter;
import android.widget.ImageView;
import android.widget.TextView;


import com.rcw.filelib.R;
import com.rcw.filelib.bean.Document;

import java.util.List;

/**
 * Created by 123 on 2017/3/14.
 */

public class FileListAdapter extends BaseAdapter<Document> {

    private List<Document> list;

    public FileListAdapter(Context context, int layoutId, List<Document> datas) {
        super(context, layoutId, datas);
    }

    public void setData(List<Document> list) {
        this.list = list;
    }

    @Override
    public void convert(ViewHolder holder, Document document, int position) {
        ImageView mFileIv = holder.getView(R.id.file_iv);
        TextView mFileNameTv = holder.getView(R.id.file_name_tv);
        TextView mFileSizeTv = holder.getView(R.id.file_size_tv);

        mFileIv.setImageResource(document.getFileType().getDrawable());
        mFileNameTv.setText(document.getTitle());
        mFileSizeTv.setText(Formatter.formatShortFileSize(context, Long.parseLong(document.getSize())));
    }
}
